﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections.Generic;

public partial class Admin_ExpertOnLine : System.Web.UI.Page
{
	private string strExpertSessionID = "";
	private PX.Chat.ChatComponent clsChatComp = new PX.Chat.ChatComponent();
	private PX.OnLine.OnLineComponent clsOnLineComp = new PX.OnLine.OnLineComponent();
	private string strQuestionSessionID = "";		// 专家要回答的提问者SessionID
	private int nExpertUserID = 0;
	private PX.Config clsConfig = new PX.Config();

	protected override void OnInit(EventArgs e)
	{
		base.OnInit(e);
		strExpertSessionID = Session.SessionID.ToString();
		try
		{
			nExpertUserID = Convert.ToInt32(Session["LoginUserID"]);
		}
		catch (Exception ex)
		{
			nExpertUserID = 0;
		}

		btnAnswer.Click += new EventHandler(btnAnswer_Click);

		idFrameChats.Attributes.Add("onload", "iFrameHeight('" + idFrameChats.ClientID.ToString() + "')");
		iFrameOnLineQuestion.Attributes.Add("onload", "iFrameHeight('" + iFrameOnLineQuestion.ClientID.ToString() + "')");
	}

	////////////////////////////////////////////////////////////////////////////////////////////////////
	/// <summary>
	/// 回答
	/// </summary>
	/// <param name="sender"></param>
	/// <param name="e"></param>
	void btnAnswer_Click(object sender, EventArgs e)
	{
		PX.Chat.Chat clsChat = new PX.Chat.Chat();

		clsChat.Chats = txtChat.Text;
		clsChat.QuestionSession = strQuestionSessionID;
		clsChat.ExpertSession = strExpertSessionID;
		clsChat.UserID = nExpertUserID;
		clsChat.DateTime = System.DateTime.Now.ToString();
		clsChat.QorA = clsConfig.nChat_Answer;

		clsChatComp.Add(clsChat);

		txtChat.Text = "";
		//ShowChat();
	}
	////////////////////////////////////////////////////////////////////////////////////////////////////

	protected void Page_Load(object sender, EventArgs e)
	{
		
		//ShowChat();

		try
		{
			strQuestionSessionID = Request["QuestionSessionID"].ToString();
			//strQuestionSessionID = Session["NowQuestionSessionID"].ToString();
			ShowNowAnswer();
		}
		catch (Exception ex)
		{
			strQuestionSessionID = "";
		}

		if (strQuestionSessionID != "")
		{
			btnAnswer.Enabled = true;
		}
		else
		{
			btnAnswer.Enabled = false;
		}
	}

	//////////////////////////////////////////////////////////////////////////////////////////////////////
	///// <summary>
	///// 显示登录专家交流记录
	///// </summary>
	//private void ShowChat()
	//{
	//        List<PX.Chat.Chat> listChats = new List<PX.Chat.Chat>();

	//        listChats = clsChatComp.QueryExpertChats(strExpertSessionID);
	//        for (int i = 0; i < listChats.Count; i++)
	//        {
	//                TextBox txtChat = new TextBox();
	//                Panel pChat = new Panel();
	//                Panel pChatStatus = new Panel();
	//                Label labStatus = new Label();

	//                PX.OnLine.OnLine clsQuestion = new PX.OnLine.OnLine();

	//                pChat.CssClass = "divChat";
	//                txtChat.TextMode = TextBoxMode.MultiLine;
	//                txtChat.CssClass = "txtChat";

	//                clsQuestion = clsOnLineComp.Query(listChats[i].QuestionSession);

	//                if (clsQuestion != null)
	//                {
	//                        if (listChats[i].QorA == clsConfig.nChat_Question)
	//                        {
	//                                labStatus.Text = clsQuestion.Name + "对您说";
	//                        }
	//                        else
	//                        {
	//                                labStatus.Text = "您对" + clsQuestion.Name + "说";
	//                        }
	//                }
	//                pChatStatus.Controls.Add(labStatus);

	//                txtChat.Text = listChats[i].Chats;

	//                pChat.Controls.Add(pChatStatus);
	//                pChat.Controls.Add(txtChat);

	//                pChats.Controls.Add(pChat);
	//        }
	//}
	//////////////////////////////////////////////////////////////////////////////////////////////////////

	////////////////////////////////////////////////////////////////////////////////////////////////////
	private void ShowNowAnswer()
	{
		PX.OnLine.OnLine clsQuestion = new PX.OnLine.OnLine();

		clsQuestion = clsOnLineComp.Query(strQuestionSessionID);
		if (clsQuestion != null)
		{
			labNowQuestion.Text = "您正在回答'" + clsQuestion.Name + "'";
		}
	}
	////////////////////////////////////////////////////////////////////////////////////////////////////
}
